﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MaterialDesignThemes.Wpf;
using MyToDo.Common;
using MyToDo.Extensions;
using Prism.Events;
using Prism.Services.Dialogs;

namespace MyToDo.Views
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : Window
    {
        private readonly IDialogHostService dialogHost;

        public MainView(IEventAggregator aggregator, IDialogHostService dialogHost)
        {
            InitializeComponent();

            aggregator.RegisterMessage(args =>
            {
                snackbar.MessageQueue?.Enqueue(args);
            },"Main");

            //注册等待消息窗口
            aggregator.Register(args =>
            {
                DialogHost.IsOpen = args.IsOpen;
                if (DialogHost.IsOpen)
                {
                    DialogHost.DialogContent = new ProgressView();
                }
            });
            btnMin.Click += (s, a) =>
            {
                this.WindowState = WindowState.Minimized;
            };
            btnMax.Click += (s, a) =>
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    this.WindowState = WindowState.Normal;
                }
                else
                {
                    this.WindowState = WindowState.Maximized;
                }
            };
            btnClose.Click += async (s, a) =>
            {
                var dialogResult = await dialogHost.Question("温馨提示", "确认关闭窗口?");
                if (dialogResult.Result != ButtonResult.OK)
                {
                    return;
                }
                this.Close();
            };

            ColorZone.MouseMove += (s, e) =>
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    this.DragMove();
                }
            };

            ColorZone.MouseDoubleClick += (s, e) =>
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    this.WindowState = WindowState.Normal;
                }
                else
                {
                    this.WindowState = WindowState.Maximized;
                }
            };

            menuBar.SelectionChanged += (s, e) =>
            {
                drawerHost.IsLeftDrawerOpen = false;
            };
            this.dialogHost = dialogHost;
        }
    }
}
